import express from "express";
import * as dbConfig from "../config/db-config.js";

const router = express.Router();

router.get("/", async (req, res) => {
  try {
    const config = await dbConfig.loadConfig();
    res.json({ success: true, config });
  } catch (error) {
    res.status(500).json({ success: false, message: error.message });
  }
});

router.post("/", async (req, res) => {
  try {
    const { source, target } = req.body;
    await dbConfig.saveConfig({ source, target });
    res.json({ success: true, message: "配置保存成功" });
  } catch (error) {
    res.status(500).json({ success: false, message: error.message });
  }
});

export default router;
